package cn.z2huo.productcenter.management.app.dao.impl.risk;

import cn.z2huo.productcenter.enums.flag.AvailableFlagEnum;
import cn.z2huo.productcenter.management.app.dao.api.risk.RiskDAO;
import cn.z2huo.productcenter.mapper.risk.RiskMapper;
import cn.z2huo.productcenter.model.dataobject.risk.RiskDO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * <p>
 *
 * @author z2huo
 */
@Repository
@RequiredArgsConstructor
public class RiskDAOImpl implements RiskDAO {

    private final RiskMapper riskMapper;

    @Override
    public Long countRiskByCode(String riskCode) {
        LambdaQueryWrapper<RiskDO> queryWrapper = Wrappers.lambdaQuery(RiskDO.class);
        queryWrapper.eq(RiskDO::getRiskCode, riskCode);
        return riskMapper.selectCount(queryWrapper);
    }

    /**
     * <p>获取所有有效的产品代码
     * @return  产品代码列表
     */
    public List<String> listValidRisk() {
        LambdaQueryWrapper<RiskDO> queryWrapper = Wrappers.lambdaQuery(RiskDO.class);
        queryWrapper.select(RiskDO::getRiskCode)
                .eq(RiskDO::getAvailableFlag, AvailableFlagEnum.AVAILABLE.getValue());
        List<String> riskCodeList = riskMapper.selectObjs(queryWrapper);
        return riskCodeList;
    }

    @Override
    public Long countValidRisk() {
        LambdaQueryWrapper<RiskDO> queryWrapper = Wrappers.lambdaQuery(RiskDO.class);
        queryWrapper.eq(RiskDO::getAvailableFlag, AvailableFlagEnum.AVAILABLE.getValue());
        Long count = riskMapper.selectCount(queryWrapper);
        return count;
    }
}

